package com.itheima.web.controller;

import com.aliyuncs.utils.StringUtils;
import com.itheima.domain.db.UserInfo;
import com.itheima.vo.MovementVo;
import com.itheima.vo.PageBeanVo;
import com.itheima.web.manager.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserController {
    @Autowired
    private UserManager userManager;


    //分页查询用户列表
    @GetMapping("/manage/users")
    public PageBeanVo findUserList(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize
    ) {

        //调用manager查询
        return userManager.findUserList(pageNum, pageSize);
    }

    //查询用户个人详细信息
    @GetMapping("/manage/users/{userID}")
    public UserInfo findUserInfo(@PathVariable("userID") Long userId) {
        //调用manager根据用户id查询其详情信息
        return userManager.findUserInfo(userId);
    }


    //查询用户发布的小视频
    @GetMapping("/manage/videos")
    public PageBeanVo findUserVideoList(Long uid,
                                        @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return userManager.findUserVideoList(uid,pageNum,pageSize);
    }


    //查询用户发布的动态(审核动态列表)
    @GetMapping("/manage/messages")
    public PageBeanVo findMovementList(
            Long uid, String state,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {

        //转换
        Integer stateInt = null;
        if (StringUtils.isNotEmpty(state)){
            stateInt = Integer.parseInt(state);
        }

        //调用manager
        return userManager.findMovementList(uid,stateInt,pageNum,pageSize);
    }


    //查询用户动态详情
    @GetMapping("/manage/messages/{id}")
    public MovementVo findMovementDetail(@PathVariable("id") String movementId){
        return userManager.findMovementDetail(movementId);
    }

    //查询用户动态评论列表
    @GetMapping("/manage/messages/comments")
    public PageBeanVo findMovementCommentList(
            @RequestParam(value = "messageID") String movementId,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize
    ) {
        return userManager.findMovementCommentList(movementId,pageNum,pageSize);
    }

    //动态评审通过
    @PostMapping("/manage/messages/pass")
    public Map MovementPass(@RequestBody List<String> movementId){
         Map<String,String> map = new HashMap<>();
         String message = userManager.findMovementPass(movementId);
         map.put("message",message);
         return map;
    }

    //动态评审未通过
    @PostMapping("/manage/messages/reject")
    public Map MovementReject(@RequestBody List<String> movementId){
        Map<String,String> map = new HashMap<>();
        String message = userManager.findMovementReject(movementId);
        map.put("message",message);
        return map;
    }
}
